<template>
    <div v-if="dialogVisible==true">
        <el-table class="domlayerstable"   :data="alldws"  border stripe   size="mini">
                <el-table-column prop="idmax" width="80" label="标识"  >
                    <template slot-scope="scope">
                        <img class="default-image" :src="$store.state.images.danghui" style="width：45px;height:45px;"> 
                    </template> 
                </el-table-column>
                <el-table-column  type="index" label="序号" width="80" align="center" ></el-table-column>
                <el-table-column prop="name" type="text" label="名称" width="270" align="center"></el-table-column>
                <el-table-column prop="alias" type="text" label="别名" width="180" align="center"></el-table-column>
                <el-table-column prop="createtime" type="text" label="创建时间" width="80" align="center"></el-table-column>
                <el-table-column prop="dwid" type="text" label="党委序号" width="80" align="center"></el-table-column>
                <el-table-column prop="dzbid" type="text" label="党支部序号" width="100" align="center"></el-table-column>
                <el-table-column prop="type" type="text" label="党组织类型" width="100" align="center"></el-table-column>
                <el-table-column align="right" width="120">
                    <template slot="header" slot-scope="scope">
                        <el-button  size="mini"    @click="add('add')">添加</el-button>
                    </template>
                    <template slot-scope="scope">
                        <el-dropdown trigger="click" @command="handleCommand">
                            <span class="el-dropdown-link">操作<i class="el-icon-caret-bottom el-icon--right"></i></span>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item class="clearfix" :command="{data:scope.row,typed:'edit'}">编辑</el-dropdown-item>
                                <el-dropdown-item class="clearfix" :command="{data:scope.row,typed:'delete'}">删除</el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </template>
                </el-table-column>
            </el-table>
        <!-- <el-dialog  :title="title" :visible.sync="dialogVisible"  width='1050px' append-to-body v-dialogDrag :modal="false" :close-on-click-modal="false">
            
        </el-dialog> -->
        <dwedit ref='dwedit' v-on:Hidedwedit="DoGetZbById"></dwedit>
    </div>
</template>
<script>
import dwedit from './dwedit.vue';
import {mapActions} from 'vuex';
export default {
    data() {
        return {
            title:"党委编辑",
            dialogVisible: false,
            alldws:[],
            loading:true,
            // visible:false,
        };
    },
    components: {
        dwedit
    },
    mounted() {
        
    },
    watch: {
        dialogVisible: function (n, o) {
            if(n==true){
                this.DoGetZbById();
            }
            else{
                this.alldws=[];
            }
        },
        visible: function (n) {
            if(n==true){
                this.dialogVisible=false
            }
            else{
               this.dialogVisible=true
            }
        }
    },
    methods: {
        ...mapActions(['GetZbById']),
        DoGetZbById(){
            this.alldws=[];
            let _this = this;
            let dwdzbid={};
            if (this.$store.state.user.operation == 0) 
            {
                this.title=='党委编辑'
                dwdzbid.dwid=-1;dwdzbid.dzbid=-1;
            }
            else if (this.$store.state.user.operation == 1) {
                this.title=='党支部编辑'
                dwdzbid.dwid=this.$store.state.user.dwid;dwdzbid.dzbid=-1;
            }
            this.GetZbById(dwdzbid)
            .then(function (e) {
                if (typeof e === "object") {
                    _this.alldws.push(e.PostThis);
                    for (let index = 0; index < e.childs.length; index++) {
                        const element = e.childs[index];
                        _this.alldws.push(element);
                    }
                }
            });
        },
        add(value,row){
            this.$refs.dwedit.$data.dialogVisible=true;
            if(this.title=='党委编辑'){
                this.$refs.dwedit.$data.needType=true;
                if(value=='add'){
                    this.$refs.dwedit.$data.rowdata.dwid=this.alldws.length+1;
                    this.$refs.dwedit.$data.rowdata.dzbid=-1;
                }
                else if(value=='edit'){
                     this.$refs.dwedit.$data.rowdata.dwid=row.dwid;
                    this.$refs.dwedit.$data.rowdata.dzbid=row.dzbid;
                    this.$refs.dwedit.$data.rowdata.name=row.name;
                    this.$refs.dwedit.$data.rowdata.alias=row.alias;
                    this.$refs.dwedit.$data.rowdata.createtime=row.createtime;
                    this.$refs.dwedit.$data.type=row.type;

                }
                this.$refs.dwedit.$data.title='党委编辑属性'
            }
            else if(this.title=='党支部编辑'){
                this.$refs.dwedit.$data.needType=false;
                if(value=='add'){
                    this.$refs.dwedit.$data.rowdata.dwid=this.$store.state.DwId_DzbI.dwid;
                    this.$refs.dwedit.$data.rowdata.dzbid=this.alldws.length+1;
                }
                else if(value=='edit'){
                    this.$refs.dwedit.$data.rowdata.dwid=row.dwid;
                    this.$refs.dwedit.$data.rowdata.dzbid=row.dzbid;
                    this.$refs.dwedit.$data.rowdata.name=row.name;
                    this.$refs.dwedit.$data.rowdata.alias=row.alias;
                    this.$refs.dwedit.$data.rowdata.createtime=row.createtime;
                }
                this.$refs.dwedit.$data.title='党支部编辑属性'
            }
            
        },
        DoDelete(row)
        {
            let postdata={
                type:"Deletedwdzb",
                split:JSON.stringify({
                    dwid:row.dwid,
                    dzbid:row.dzbid
                })
            }
            let _this=this;
            this.$Common.AjaxPost(postdata,true)
            .then(function(e){
                _this.$message({
                    type: 'success',
                    message: '删除成功!'
                });
                // _this.$emit('onReshdws');
                _this.DoGetZbById();
            });
        },
        showthis(){
            this.$emit('onReshdws');
            this.dialogVisible=true;
        },
        handleCommand(value){
            if(value.typed=="edit"){
                 this.$confirm('保存操作可能有改动, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.add('edit',value.data)
                }).catch(() => {});
            }
            else if(value.typed=="delete"){//删除
                this.$confirm('此操作将永久该组织, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.DoDelete(value.data);
                }).catch(() => {});
            }
        },
    },
    
}
</script>
<style >

</style>